package com.vtmer.controller;

import com.vtmer.entity.IntervStatus;
import com.vtmer.entity.Progress;
import com.vtmer.entity.RegistrationForm;
import com.vtmer.service.ProgressService;
import com.vtmer.service.RegistrationFormService;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.ResultMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author Colin_Knight
 * @create 2022/10/9 14:31
 */
@RestController
@Slf4j
@RequestMapping("/administrators")
public class ProgressController {

    @Resource
    private ProgressService progressService;

    @Autowired
    private RegistrationFormService registrationFormService;

    @PutMapping("/updateFailStatus/{studId}")
    @Transactional
    public IntervStatus updateFailStatus(@PathVariable String studId,
                                         @RequestParam("fail") String fail){
        int f = Integer.parseInt(fail);
        log.info("调用updateFailStatus()方法");
        Progress progress = progressService.updateFailAssessmResultByStudId(studId, f);
        return new IntervStatus(progress);
    }

    @PostMapping("/getProgress/{studId}")
    public IntervStatus getProgress(@PathVariable long studId) {
        RegistrationForm registrationForm = getProgressByStudIdAndName(studId);
        Assert.notNull(registrationForm,"没有该用户");
        return new IntervStatus(registrationForm);
    }

    private RegistrationForm getProgressByStudIdAndName(@PathVariable long studId){
        return registrationFormService.getProgressByStudIdAndName(studId);
    }

}
